package com.wxp.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.Length;


@Entity
@Table(name = "t_permission")
public class Permission implements Serializable{
	
	@Id
    @Column(name = "PERMISSION_ID_", nullable = false, insertable = true, updatable = false)
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "com.modules.utils.IDGenerator")
	private String permissionId;
	
	@Length(max=64)
	@Column(name="ROLE_CODE_" ,nullable = true ,unique = false ,insertable = true ,updatable = true,length=64)
	private String roleCode;
	
	@Length(max=64)
	@Column(name="OPERATOR_ID_" ,nullable = true ,unique = false ,insertable = true ,updatable = true,length=64)
	private String operatorId;
	
	@Length(max=64)
	@Column(name="OPERATOR_NAME_" ,nullable = true ,unique = false ,insertable = true ,updatable = true,length=64)
	private String operatorName;
	
	
	@Length(max=64)
	@Column(name="PERMISSION_" ,nullable = true ,unique = false ,insertable = true ,updatable = true,length=64)
	private String permission;
	
	 @ManyToOne(fetch = FetchType.EAGER)
	 @Cascade(value={CascadeType.SAVE_UPDATE} )	
	 @JoinColumns({
			@JoinColumn(name = "ROLE_CODE_",nullable = false, insertable = false, updatable = false) 
		})
	 private Role role ;
	
	public String getPermissionId() {
		return permissionId;
	}
	public void setPermissionId(String permissionId) {
		this.permissionId = permissionId;
	}
	public String getRoleCode() {
		return roleCode;
	}
	public void setRoleCode(String roleCode) {
		this.roleCode = roleCode;
	}
	public String getOperatorId() {
		return operatorId;
	}
	public void setOperatorId(String operatorId) {
		this.operatorId = operatorId;
	}
	
	
	public String getOperatorName() {
		return operatorName;
	}
	public void setOperatorName(String operatorName) {
		this.operatorName = operatorName;
	}
	public String getPermission() {
		return permission;
	}
	public void setPermission(String permission) {
		this.permission = permission;
	}
	
	
	
	
	
	
	public Role getRole() {
		return role;
	}
	public void setRole(Role role) {
		this.role = role;
	}
	@Override
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getPermissionId())
			.toHashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if(obj instanceof Permission == false) return false;
		if(this == obj) return true;
		Permission other = (Permission)obj;
		return new EqualsBuilder()
			.append(getPermissionId(),other.getPermissionId())
			.isEquals();
	}
}
